// RBO工作流设计器统一导出
export { default as RboWorkflowDesignerV1 } from './v1/RboWorkflowDesigner.vue';
export { default as RboWorkflowDesignerV2 } from './v2/RboWorkflowDesigner.vue';

// 默认导出V2版本（推荐使用）
export { default as RboWorkflowDesigner } from './v2/RboWorkflowDesigner.vue';

// 添加默认导出
export { default } from './v2/RboWorkflowDesigner.vue';

// 类型定义
export interface RboWorkflowNode {
  id: string;
  type: string;
  label: string;
  icon: string;
  config: Record<string, any>;
  position: { x: number; y: number };
}

export interface RboWorkflowConnection {
  id: string;
  from: string;
  to: string;
  label?: string;
}

export interface RboWorkflowData {
  nodes: RboWorkflowNode[];
  edges: RboWorkflowConnection[];
  viewport: { x: number; y: number; zoom: number };
}

// 节点类型枚举
export enum RboNodeType {
  // 行为节点
  BEHAVIOR_EXECUTE = 'behavior_execute',
  // 控制节点
  CONDITION = 'condition',
  DATA_AGGREGATE = 'data_aggregate',
  DATA_FILTER = 'data_filter',

  // 数据节点
  DATA_TRANSFORM = 'data_transform',
  DATA_VALIDATE = 'data_validate',
  DELAY = 'delay',
  EVENT_LISTEN = 'event_listen',

  // 事件节点
  EVENT_PUBLISH = 'event_publish',
  LOOP = 'loop',
  MESSAGE_RECEIVE = 'message_receive',
  MESSAGE_SEND = 'message_send',

  PARALLEL = 'parallel',
  RULE_ENGINE = 'rule_engine',
  SERVICE_CALL = 'service_call',
  WORKFLOW_SUB = 'workflow_sub',
}

// 节点类型配置
export const RBO_NODE_CONFIGS = {
  [RboNodeType.BEHAVIOR_EXECUTE]: {
    label: '行为执行',
    icon: 'ant-design:play-circle-outlined',
    category: 'behavior',
  },
  [RboNodeType.SERVICE_CALL]: {
    label: '服务调用',
    icon: 'ant-design:api-outlined',
    category: 'behavior',
  },
  [RboNodeType.WORKFLOW_SUB]: {
    label: '子工作流',
    icon: 'ant-design:branches-outlined',
    category: 'behavior',
  },
  [RboNodeType.RULE_ENGINE]: {
    label: '规则引擎',
    icon: 'ant-design:code-outlined',
    category: 'behavior',
  },
  [RboNodeType.CONDITION]: {
    label: '条件判断',
    icon: 'ant-design:question-circle-outlined',
    category: 'control',
  },
  [RboNodeType.PARALLEL]: {
    label: '并行执行',
    icon: 'ant-design:fork-outlined',
    category: 'control',
  },
  [RboNodeType.LOOP]: {
    label: '循环执行',
    icon: 'ant-design:reload-outlined',
    category: 'control',
  },
  [RboNodeType.DELAY]: {
    label: '延时等待',
    icon: 'ant-design:clock-circle-outlined',
    category: 'control',
  },
  [RboNodeType.EVENT_PUBLISH]: {
    label: '事件发布',
    icon: 'ant-design:notification-outlined',
    category: 'event',
  },
  [RboNodeType.EVENT_LISTEN]: {
    label: '事件监听',
    icon: 'ant-design:ear-outlined',
    category: 'event',
  },
  [RboNodeType.MESSAGE_SEND]: {
    label: '消息发送',
    icon: 'ant-design:message-outlined',
    category: 'event',
  },
  [RboNodeType.MESSAGE_RECEIVE]: {
    label: '消息接收',
    icon: 'ant-design:inbox-outlined',
    category: 'event',
  },
  [RboNodeType.DATA_TRANSFORM]: {
    label: '数据转换',
    icon: 'ant-design:swap-outlined',
    category: 'data',
  },
  [RboNodeType.DATA_FILTER]: {
    label: '数据过滤',
    icon: 'ant-design:filter-outlined',
    category: 'data',
  },
  [RboNodeType.DATA_AGGREGATE]: {
    label: '数据聚合',
    icon: 'ant-design:cluster-outlined',
    category: 'data',
  },
  [RboNodeType.DATA_VALIDATE]: {
    label: '数据验证',
    icon: 'ant-design:check-circle-outlined',
    category: 'data',
  },
};

// 工具函数
export const createRboNode = (
  type: RboNodeType,
  position: { x: number; y: number },
  config: Record<string, any> = {},
): RboWorkflowNode => {
  const nodeConfig = RBO_NODE_CONFIGS[type];
  return {
    id: `node_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`,
    type,
    label: nodeConfig.label,
    icon: nodeConfig.icon,
    position,
    config: {
      ...config,
      category: nodeConfig.category,
    },
  };
};

export const createRboConnection = (
  from: string,
  to: string,
  label?: string,
): RboWorkflowConnection => {
  return {
    id: `conn_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`,
    from,
    to,
    label,
  };
};
